<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('货运订单列表')" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-10 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>业务员：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>提验人：</label>
                                <input type="text" name="vehicleInspector"/>
                            </li>
                            <li>
                                <label>订单查找：</label>
                                <input type="text" name="vehicleModel"/>
                            </li>
                            <li>
                                <label>支付方式：</label>
                                <select name="payType" th:with="type=${@dict.getType('pay_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>订单状态：</label>
                                <select name="orderType" th:with="type=${@dict.getType('order_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>中转查找：</label>
                                <input type="text" id="transitBranch" name="transitBranch"/>
                            </li>
                            <li>
                                <label>欠/返：</label>
                                <select id="refund" name="refund">
                                    <option value="0">所有</option>
                                    <option value="2">有欠付</option>
                                    <option value="1">有欠返</option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>日期筛选： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="searchPre()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="system:order:add">
                    <i class="fa fa-plus"></i> 建立订单
                </a>
                <a class="btn btn-success" onclick="$.operate.editAll()" shiro:hasPermission="system:order:edit">
                    <i class="fa fa-plus"></i> 批量发运
                </a>
                <a id="hidDiv" class="btn btn-success" onclick="$.operate.settlementAll()" shiro:hasPermission="system:order:edit">
                    <i class="fa fa-plus"></i> 批量结算
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:order:export">
                    <i class="fa fa-download"></i> 导出数据
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:order:remove">
                    <i class="fa fa-remove"></i> 删除订单
                </a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <label id="amount1" style="font-size: 15px;font-weight: bold;">运费总额：<span id="freightAmount"></span>&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <label id="amount2" style="font-size: 15px;font-weight: bold;">预付款总额：<span id="paidAmount"></span>&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <label id="amount3" style="font-size: 15px;font-weight: bold;">中介费总额：<span id="agencyFee"></span>&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <label id="amount4" style="font-size: 15px;font-weight: bold;">提成总额：<span id="commission"></span>&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <label id="amount5" style="font-size: 15px;font-weight: bold;">利润总额：<span id="profit"></span>&nbsp;&nbsp;&nbsp;&nbsp;</label>
                    <!--                <label style="font-size: 15px;font-weight: bold;">提验费总额：<span id="inspectionFee"></span>&nbsp;&nbsp;&nbsp;&nbsp;</label>-->
                <label style="font-size: 15px;font-weight: bold;" onclick="amountShow()"><a>显示隐藏总额</a></label>
            </div>
<!--            <div class="col-sm-12 select-table table-striped" style=" white-space: nowrap; overflow: hidden; overflow-x: scroll; -webkit-backface-visibility: hidden; -webkit-overflow-scrolling: touch;">-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        function fatherReload() {
            window.location.reload();
        }
        function searchPre() {
            totalA();
            var transitBranch = $("#transitBranch").val();
            if(transitBranch.length > 0){
                $.table.showColumn("transitBranch");
                $.table.showColumn("transferFee");
                $.table.showColumn("owes");
                // $.table.showColumn("transporter");
                // $.table.showColumn("transporterPhone");
                // $.table.showColumn("plateNumber");
                // $.table.showColumn("amount");
                // $.table.showColumn("refund");
            }else {
                $.table.hideColumn("transitBranch");
                $.table.hideColumn("transferFee");
                $.table.hideColumn("owes");
                // $.table.hideColumn("transporter");
                // $.table.hideColumn("transporterPhone");
                // $.table.hideColumn("plateNumber");
                // $.table.hideColumn("amount");
                // $.table.hideColumn("refund");
            }
            $.table.search("formId");
        }

        var editFlag = [[${@permission.hasPermi('system:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:order:update')}]];
        var detailFlag = [[${@permission.hasPermi('system:order:detail')}]];
        var datasPay = [[${@dict.getType('pay_type')}]];
        var datasType = [[${@dict.getType('order_type')}]];
        var datasDelete = [[${@dict.getType('is_delete')}]];
        var renewFlag = [[${@permission.hasPermi('system:order:renew')}]];
        var prefix = ctx + "system/order";

        var prefix2 = ctx + "system/finance";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                renewUrl: prefix + "/renew/{id}",
                removeUrl: prefix + "/update",
                exportUrl: prefix + "/export",
                detailUrl: prefix + "/detail/{id}",
                detailedUrl : prefix2 + "/detailed/{id}",
                editUrl : prefix + "/transport/{id}",
                modalName: "运单",
                showToggle: false,
                showColumns: false,
                showFooter: true,
                striped: true,
                rememberSelected: true,
                height: 600,
                columns: [{
                    field: 'state',
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'orderId',
                    title: '主键',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'createUser',
                    align: 'center',
                    title: '建单人'
                },
                {
                    field: 'vehicleInspector',
                    align: 'center',
                    title: '提验人'
                },
                {
                    field: 'userName',
                    align: 'center',
                    title: '业务员'
                },
                {
                    field: 'client',
                    align: 'center',
                    title: '委托人'
                },
                // {
                //     field: 'clientPhone',
                //     align: 'center',
                //     title: '委托人电话'
                // },
                {
                    field: 'vehicleModel',
                    align: 'center',
                    title: '车型'
                },
                {
                    field: 'vin',
                    align: 'center',
                    title: '车架号'
                },
                {
                    field: 'origin',
                    align: 'center',
                    title: '起始地',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 8);
                    }
                },
                {
                    field: 'dest',
                    align: 'center',
                    title: '目的地',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 8);
                    }
                },
                {
                    field: 'receiverPhone',
                    align: 'center',
                    title: '接车人电话'
                },
                {
                    field: 'freightAmount',
                    align: 'center',
                    title: '运费金额'
                },
                {
                    field: 'paidAmount',
                    align: 'center',
                    title: '预付款'
                },
                {
                    field: 'payType',
                    title: '支付方式',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datasPay, value);
                    }
                },
                {
                    field: 'orderType',
                    title: '订单状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datasType, value);
                    }
                },
                {
                    field: 'createTime',
                    align: 'center',
                    title: '建单日期',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 13);
                    }
                },
                {
                    field: 'updateTime',
                    align: 'center',
                    title: '发运日期',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 13);
                    }
                },
                {
                    field: 'notes',
                    align: 'center',
                    title: '备注',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 10);
                    }
                },
                {
                    field: 'notGive',
                    align: 'center',
                    title: '有欠返',
                    formatter: function (value, row, index) {
                        if (row.notGive) {
                            return '<span class="badge badge-danger">有欠反</span>';
                        } else {
                            return '<span class="badge badge-primary">无</span>';
                        }
                    }
                },
                {
                    field: 'notPay',
                    align: 'center',
                    title: '有欠付',
                    formatter: function (value, row, index) {
                        if (row.notPay) {
                            return '<span class="badge badge-success">有欠付</span>';
                        } else {
                            return '<span class="badge badge-primary">无</span>';
                        }
                    }
                },
                {
                    field: 'agencyFee',
                    align: 'center',
                    title: '中介费',
                },
                {
                    field: 'commission',
                    align: 'center',
                    title: '提成',
                },
                {
                    field: 'profit',
                    align: 'center',
                    title: '利润'
                },
                {
                    field: 'transitBranch',
                    title: '中转人',
                    visible: false
                },
                {
                    field: 'transferFee',
                    title: '中转费',
                    visible: false
                },
                {
                    field: 'owes',
                    title: '欠/返',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + renewFlag + '" href="javascript:void(0)" onclick="$.operate.renewFull(\'' + row.orderId + '\')"><i class="fa fa-edit"></i>详单</a> ');
                        // actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '\')"><i class="fa fa-search"></i>详情</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        $(function(){
            var url = prefix2 + "/total";
            var dataParam = $.common.formToJSON("formId");
            $.post(url, dataParam, function(result) {
                if(result == "" || result == null){
                    $("#freightAmount").html("0");
                    $("#paidAmount").html("0");
                    $("#profit").html("0");
                    $("#commission").html("0");
                    $("#inspectionFee").html("0");
                    $("#agencyFee").html("0");
                }else {
                    $("#freightAmount").html(result.freightAmount);
                    $("#paidAmount").html(result.paidAmount);
                    $("#profit").html(result.profit);
                    $("#commission").html(result.commission);
                    $("#inspectionFee").html(result.inspectionFee);
                    $("#agencyFee").html(result.agencyFee);
                }
            });
        });

        function totalA(){
            var url = prefix2 + "/total";
            var dataParam = $.common.formToJSON("formId");
            $.post(url, dataParam, function(result) {
                if(result == "" || result == null){
                    $("#freightAmount").html("0");
                    $("#paidAmount").html("0");
                    $("#profit").html("0");
                    $("#commission").html("0");
                    $("#inspectionFee").html("0");
                    $("#agencyFee").html("0");
                }else {
                    $("#freightAmount").html(result.freightAmount);
                    $("#paidAmount").html(result.paidAmount);
                    $("#profit").html(result.profit);
                    $("#commission").html(result.commission);
                    $("#inspectionFee").html(result.inspectionFee);
                    $("#agencyFee").html(result.agencyFee);
                }
            });
        }

        var v = "100";
        function amountShow(){
            if( v != "100"){
                totalA();
                v = "100";
            }else {
                $("#freightAmount").html("***");
                $("#paidAmount").html("***");
                $("#profit").html("***");
                $("#commission").html("***");
                $("#inspectionFee").html("***");
                $("#agencyFee").html("***");
                v = "101";
            }
        }
    </script>
</body>
</html>